export interface TerminalOptions {
  userId?: string;
  shell?: string;
  cwd?: string;
  env?: Record<string, string>;
  cols?: number;
  rows?: number;
}

export interface TerminalSession {
  id: string;
  userId: string;
  pid: number;
  shell: string;
  cwd: string;
  created: Date;
  lastActivity: Date;
  status: 'active' | 'terminated';
}

export interface OutputEntry {
  line: number;
  content: string;
  timestamp: Date;
}

export interface BufferStats {
  totalLines: number;
  totalBytes: number;
  estimatedTokens: number;
  bufferSize: number;
  oldestLine: number;
  newestLine: number;
}

export interface ReadOptions {
  since?: number;
  mode?: 'full' | 'head' | 'tail' | 'head-tail';
  headLines?: number;
  tailLines?: number;
  maxLines?: number;
  clean?: boolean;
}

export interface OutputResult {
  output: string;
  totalLines: number;
  nextReadFrom: number;
  hasMore: boolean;
  truncated: boolean;
  stats: {
    totalBytes: number;
    estimatedTokens: number;
    linesShown: number;
    linesOmitted: number;
  };
}

export interface StatsResult {
  terminalId: string;
  totalLines: number;
  totalBytes: number;
  estimatedTokens: number;
  bufferSize: number;
  oldestLine: number;
  newestLine: number;
  isActive: boolean;
}

export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  message?: string;
  error?: {
    code: string;
    message: string;
    details?: any;
  };
}

export type ErrorCode =
  | 'TERMINAL_NOT_FOUND'
  | 'TERMINAL_INACTIVE'
  | 'INVALID_INPUT'
  | 'WRITE_FAILED'
  | 'READ_FAILED'
  | 'KILL_FAILED'
  | 'PERMISSION_DENIED'
  | 'INTERNAL_ERROR';
